package com.dc.free.module.lawyer.controller;

import java.util.List;

import com.dc.free.module.lawyer.db.model.Lawyer;
import com.dc.free.module.lawyer.service.LawyerService;
import com.alibaba.fastjson.JSON;
import com.dc.free.common.base.BaseController;

/**
 * 
 * @author quan
 * @since 2018-06-22
 */
public class LawyerController extends BaseController {
																													
	private Lawyer getLawyer() {
		return JSON.parseObject(getParameters().toJSONString(), Lawyer.class);
	}
	
	public void insert() {
		Lawyer lawyer = getLawyer();
		boolean flag = LawyerService.insert(lawyer);
		if(flag) renderOk(new Lawyer().setCardNumber(lawyer.getCardNumber()));
		else renderError();
	}
	
	public void update() {
		Lawyer lawyer = getLawyer();
		boolean flag = LawyerService.update(lawyer) > 0;
		if(flag) renderOk();
		else renderError();
	}
	
	public void save() {
		Lawyer lawyer = getLawyer();
		boolean flag = LawyerService.save(lawyer);
		if(flag) renderOk(new Lawyer().setCardNumber(lawyer.getCardNumber()));
		else renderError();
	}
	
	public void delete() {
		Lawyer lawyer = getLawyer();
		boolean flag = LawyerService.delete(lawyer) > 0;
		if(flag) renderOk();
		else renderError();
	}
	
	public void get() {
		Lawyer lawyer = getLawyer();
		lawyer = LawyerService.get(lawyer);
		renderOk(lawyer);
	}
	
	public void list() {
		Lawyer lawyer = getLawyer();
		List<Lawyer> lawyers = LawyerService.list(lawyer);
		renderOk(lawyers);
	}
	
	public void paginate() {
		Lawyer lawyer = getLawyer();
		int pageSize = getParaToInt("pageSize", 10);
		int pageNumber = getParaToInt("pageNumber", 1);
		renderOk(LawyerService.paginate(lawyer, pageSize, pageNumber));
	}
	
}